package com.monster.servlet.player;

import com.monster.pojo.Song;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

@WebServlet("/music/player")
public class PlayServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String closed = request.getParameter("close");
        HttpSession session = request.getSession();
        ArrayList<Song> songs = null;
        while ("false".equals(closed)) {
            if (session.getAttribute("playChange") != null) {
                request.getRequestDispatcher("playerList.jsp").forward(request, response);
                session.removeAttribute("playChange");
                break;
            } else {
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
